home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / word / c_pretty.zip / C_PRETTY.TXT < prev   
Text File  |  1993-06-10  |  8KB  |  177 lines

  1. 'Free WordBasic Macro to make C programming code look nicer when printed.
  2. '(for Word for Windows 2)
  3.  
  4. ' Instructions: open this document in MS-Word for Windows, select the whole document
  5. ' and copy it to the clipboard. Open a new macro (i.e. the 'Tools' menu, 'Macro...'), call it
  6. ' whatever you like. Paste this document into that macro, and voila! there you have it.
  7. ' I have found that it is more useful if you then give the macro a command key equivalent, or put 
  8. ' a tool in the Toolbar (I use the capital 'C' so that I know that it is for my 'C' programs).
  9.  
  10. ' Written by Philip Ryan, DSTO Materials Research Laboratory, Melbourne, Australia.
  11. ' email: ryanph@mrl.dsto.gov.au
  12.  
  13. ' Do anything you like with this, if you make it better, send me a copy.
  14. ' Note that this could easily be converted to use with Pascal or any other language.
  15.  
  16. Sub MAIN
  17.  
  18. ' The StartOfDocument statement is needed to ensure that the ReplaceAll works properly.
  19. StartOfDocument
  20.  
  21. ' For the first set of words, make the format of the replaced text be bold only.
  22. EditReplaceChar .Bold = 1, .Italic = 0, .Underline = 0, .Strikeout = 0
  23.  
  24. ' Start doing the replacing.
  25. EditReplace .Find = "float", .Replace = "float", .Format = 1, .WholeWord = 1, .ReplaceAll
  26. StartOfDocument
  27. EditReplace .Find = "long", .Replace = "long", .Format = 1, .WholeWord = 1, .ReplaceAll
  28. StartOfDocument
  29. EditReplace .Find = "int", .Replace = "int", .Format = 1, .WholeWord = 1, .ReplaceAll
  30. StartOfDocument
  31. EditReplace .Find = "double", .Replace = "double", .Format = 1, .WholeWord = 1, .ReplaceAll
  32. StartOfDocument
  33. EditReplace .Find = "if", .Replace = "if", .Format = 1, .WholeWord = 1, .ReplaceAll
  34. StartOfDocument
  35. EditReplace .Find = "then", .Replace = "then", .Format = 1, .WholeWord = 1, .ReplaceAll
  36. StartOfDocument
  37. EditReplace .Find = "else", .Replace = "else", .Format = 1, .WholeWord = 1, .ReplaceAll
  38. StartOfDocument
  39. EditReplace .Find = "while", .Replace = "while", .Format = 1, .WholeWord = 1, .ReplaceAll
  40. StartOfDocument
  41. EditReplace .Find = "until", .Replace = "until", .Format = 1, .WholeWord = 1, .ReplaceAll
  42. StartOfDocument
  43. EditReplace .Find = "repeat", .Replace = "repeat", .Format = 1, .WholeWord = 1, .ReplaceAll
  44. StartOfDocument
  45. EditReplace .Find = "return", .Replace = "return", .Format = 1, .WholeWord = 1, .ReplaceAll
  46. StartOfDocument
  47. EditReplace .Find = "break", .Replace = "break", .Format = 1, .WholeWord = 1, .ReplaceAll
  48. StartOfDocument
  49. EditReplace .Find = "case", .Replace = "case", .Format = 1, .WholeWord = 1, .ReplaceAll
  50. StartOfDocument
  51. EditReplace .Find = "switch", .Replace = "switch", .Format = 1, .WholeWord = 1, .ReplaceAll
  52. StartOfDocument
  53. EditReplace .Find = "repeat", .Replace = "repeat", .Format = 1, .WholeWord = 1, .ReplaceAll
  54. StartOfDocument
  55. EditReplace .Find = "register", .Replace = "register", .Format = 1, .WholeWord = 1, 
  56. .ReplaceAll
  57. StartOfDocument
  58. EditReplace .Find = "volatile", .Replace = "volatile", .Format = 1, .WholeWord = 1, 
  59. .ReplaceAll
  60. StartOfDocument
  61. EditReplace .Find = "union", .Replace = "union", .Format = 1, .WholeWord = 1, .ReplaceAll
  62. StartOfDocument
  63. EditReplace .Find = "typedef", .Replace = "typedef", .Format = 1, .WholeWord = 1, 
  64. .ReplaceAll
  65. StartOfDocument
  66. EditReplace .Find = "struct", .Replace = "struct", .Format = 1, .WholeWord = 1, .ReplaceAll
  67. StartOfDocument
  68. EditReplace .Find = "auto", .Replace = "auto", .Format = 1, .WholeWord = 1, .ReplaceAll
  69. StartOfDocument
  70. EditReplace .Find = "const", .Replace = "const", .Format = 1, .WholeWord = 1, .ReplaceAll
  71. StartOfDocument
  72. EditReplace .Find = "continue", .Replace = "continue", .Format = 1, .WholeWord = 1, 
  73. .ReplaceAll
  74. StartOfDocument
  75. EditReplace .Find = "default", .Replace = "default", .Format = 1, .WholeWord = 1, .ReplaceAll
  76. StartOfDocument
  77. EditReplace .Find = "enum", .Replace = "enum", .Format = 1, .WholeWord = 1, .ReplaceAll
  78. StartOfDocument
  79. EditReplace .Find = "extern", .Replace = "extern", .Format = 1, .WholeWord = 1, .ReplaceAll
  80. StartOfDocument
  81. EditReplace .Find = "goto", .Replace = "goto", .Format = 1, .WholeWord = 1, .ReplaceAll
  82. StartOfDocument
  83. EditReplace .Find = "short", .Replace = "short", .Format = 1, .WholeWord = 1, .ReplaceAll
  84. StartOfDocument
  85. EditReplace .Find = "signed", .Replace = "signed", .Format = 1, .WholeWord = 1, .ReplaceAll
  86. StartOfDocument
  87. EditReplace .Find = "unsigned", .Replace = "unsigned", .Format = 1, .WholeWord = 1, 
  88. .ReplaceAll
  89. StartOfDocument
  90. EditReplace .Find = "sizeof", .Replace = "sizeof", .Format = 1, .WholeWord = 1, .ReplaceAll
  91. StartOfDocument
  92. EditReplace .Find = "static", .Replace = "static", .Format = 1, .WholeWord = 1, .ReplaceAll
  93. StartOfDocument
  94. EditReplace .Find = "void", .Replace = "void", .Format = 1, .WholeWord = 1, .ReplaceAll
  95. StartOfDocument
  96. EditReplace .Find = "FILE", .Replace = "FILE", .Format = 1, .WholeWord = 1, .MatchCase = 
  97. 1, .ReplaceAll
  98.  
  99. 'For this next set, which is a small subset of the standard libraries, make the replaced text 
  100. 'format be italic only.
  101.  
  102. EditReplaceChar .Bold = 0, .Italic = 1, .Underline = 0, .Strikeout = 0
  103. StartOfDocument
  104. EditReplace .Find = "main", .Replace = "main", .Format = 1, .WholeWord = 1, .ReplaceAll
  105. StartOfDocument
  106. EditReplace .Find = "printf", .Replace = "printf", .Format = 1, .WholeWord = 1, .ReplaceAll
  107. StartOfDocument
  108. EditReplace .Find = "fprintf", .Replace = "fprintf", .Format = 1, .WholeWord = 1, .ReplaceAll
  109. StartOfDocument
  110. EditReplace .Find = "scanf", .Replace = "scanf", .Format = 1, .WholeWord = 1, .ReplaceAll
  111. StartOfDocument
  112. EditReplace .Find = "fscanf", .Replace = "fscanf", .Format = 1, .WholeWord = 1, .ReplaceAll
  113. StartOfDocument
  114. EditReplace .Find = "getc", .Replace = "getc", .Format = 1, .WholeWord = 1, .ReplaceAll
  115. StartOfDocument
  116. EditReplace .Find = "getch", .Replace = "getch", .Format = 1, .WholeWord = 1, .ReplaceAll
  117. StartOfDocument
  118. EditReplace .Find = "getchar", .Replace = "getchar", .Format = 1, .WholeWord = 1, .ReplaceAll
  119. StartOfDocument
  120. EditReplace .Find = "putc", .Replace = "putc", .Format = 1, .WholeWord = 1, .ReplaceAll
  121. StartOfDocument
  122. EditReplace .Find = "putch", .Replace = "putch", .Format = 1, .WholeWord = 1, .ReplaceAll
  123. StartOfDocument
  124. EditReplace .Find = "putchar", .Replace = "putchar", .Format = 1, .WholeWord = 1, 
  125. .ReplaceAll
  126.  
  127. StartOfDocument
  128.  
  129. ' For the last set, the C pre-processor directives, make the format bold-italic only.
  130. EditReplaceChar .Bold = 1, .Italic = 1, .Underline = 0, .Strikeout = 0
  131. EditReplace .Find = "#include", .Replace = "#include", .Format = 1, .WholeWord = 1, 
  132. .ReplaceAll
  133. StartOfDocument
  134. EditReplace .Find = "#define", .Replace = "#define", .Format = 1, .WholeWord = 1, 
  135. .ReplaceAll
  136. StartOfDocument
  137. EditReplace .Find = "#ifdef", .Replace = "#ifdef", .Format = 1, .WholeWord = 1, .ReplaceAll
  138. StartOfDocument
  139. EditReplace .Find = "#error", .Replace = "#error", .Format = 1, .WholeWord = 1, .ReplaceAll
  140. StartOfDocument
  141. EditReplace .Find = "#if", .Replace = "#if", .Format = 1, .WholeWord = 1, .ReplaceAll
  142. StartOfDocument
  143. EditReplace .Find = "#ifndef", .Replace = "#ifndef", .Format = 1, .WholeWord = 1, .ReplaceAll
  144. StartOfDocument
  145. EditReplace .Find = "#else", .Replace = "#else", .Format = 1, .WholeWord = 1, .ReplaceAll
  146. StartOfDocument
  147. EditReplace .Find = "#elif", .Replace = "#elif", .Format = 1, .WholeWord = 1, .ReplaceAll
  148. StartOfDocument
  149. EditReplace .Find = "#endif", .Replace = "#endif", .Format = 1, .WholeWord = 1, .ReplaceAll
  150. StartOfDocument
  151. EditReplace .Find = "#pragma", .Replace = "#pragma", .Format = 1, .WholeWord = 1, 
  152. .ReplaceAll
  153.  
  154. ' Now, to format the comments.
  155. StartOfDocument
  156.  
  157. ' Look for the normal comment string delimiter of C.
  158. EditFind .Find = "/*",  .Direction = 2
  159.  
  160. ' Keep on searching for comment blocks.
  161. While EditFindFound()
  162.     ExtendSelection "*"
  163.     ExtendSelection "/"
  164.     FormatCharacter .Italic = 1, .Bold = 0
  165.     Cancel
  166. ' To ensure that the next found character is in the _next_ comment block,
  167. ' we set the findchar type to italic _off_. (Since otherwise the insertion
  168. ' point always remains at the start of the last selection.)
  169.     EditFindChar .Italic = 0
  170.     EditFind
  171. Wend
  172.  
  173. End Sub
  174.  
  175.  
  176.  
  177.